const express = require("express");
// const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");

const app = express();

app.use( express.static("./www") );
// app.use( bodyParser() );
app.use(express.urlencoded({extended:false}))
app.use(express.json());
app.use(cookieParser());

app.get("/getBanner", (req, res, next)=>{
    // 解析get数据
    console.log(req.query, 1);

    // 设置cookie
    // res.cookie("token", "haffagsiberwog");

    // 获取cookie，需要提前加载中间件
    console.log(req.cookies);
    console.log(req.cookies.token);

    res.send({a:10,b:20});
})

app.post("/setBanner", (req, res, next)=>{
    // 解析post数据，注意，需要提前加载中间件
    console.log(req.body, 2);
    res.end();
})

app.listen(3000);

